package fr.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import fr.business.ManageParticipationsBusinessService;
import fr.form.synthese.SyntheseEcranParticipations;
import fr.form.synthese.SyntheseParticipation;
import fr.utilities.Constantes.StatutParticipation;

@Controller
@RequestMapping("/superuser")
public class ManageSuParticipationsController {

	@Autowired
	private ManageParticipationsBusinessService bs;

	@RequestMapping("/showParticipations")
	public String listApplications(Map<String, Object> map,@ModelAttribute("ParticipationsSuperUserForm")
	SyntheseEcranParticipations ecran, BindingResult result, HttpSession session) {
		
		List<Integer> listeStatut = new ArrayList<Integer>();
		listeStatut.add(StatutParticipation.VALIDEE.getCode());
		listeStatut.add(StatutParticipation.VALIDEE_SU.getCode());
		listeStatut.add(StatutParticipation.NON_VALIDEE_SU.getCode());
		
		List<SyntheseParticipation> participations = bs.readParticipationsByParam(listeStatut,null,null);
		map.put("listParticipation",participations);
		
		Map<Integer,String> mapStatut = new HashMap<Integer,String>();
		for(StatutParticipation statut : StatutParticipation.values()){
			mapStatut.put(statut.getCode(),statut.getLibelle());
		}
		map.put("listeStatut", mapStatut);

		return "superUser/showParticipations";

	}
	
	@ResponseBody
	@RequestMapping(value="/validerParticipation",method=RequestMethod.POST)
	public String validerParticipation(@RequestParam(value="id") Integer id){
		return bs.validerParticipation(id);
	}

	@ResponseBody
	@RequestMapping(value="/refuserParticipation",method=RequestMethod.POST)
	public String refuserParticipation(@RequestParam(value="id") Integer id){
		return bs.refuserParticipation(id);
	}

}
